/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cx1.dao.impl;

import com.ibatis.sqlmap.client.SqlMapClient;
import java.util.ArrayList;
import java.util.List;
import org.cx1.dao.api.ILeadDao;
import org.cx1.model.Lead;

/**
 *
 * @author ECH
 */
public class LeadDao implements ILeadDao {

    private SqlMapClient sqlMapClient;

    public LeadDao() {
        sqlMapClient = IbatisConnectionFactory.getSqlMapClient();
    }
    
    @Override
    public List<Lead> getAll() {
        List<Lead> amenities = new ArrayList<Lead>();        
        try {
            amenities = sqlMapClient.queryForList("lead.getAll");
        } catch (Exception ex) {
            ex.printStackTrace();
        }        
        return amenities;
    }

    @Override
    public String add(Lead lead) {
        String leadId = "";        
        try {
            sqlMapClient.insert("lead.add", lead);
            leadId = lead.getId();            
        } catch (Exception ex) {
            ex.printStackTrace();
        }        
        return leadId;
    }

    @Override
    public int deleteById(String id) {
        int noOfRowsAffected = 0;        
        try {
            noOfRowsAffected = sqlMapClient.delete("lead.deleteById", id);
        } catch (Exception ex) {
            ex.printStackTrace();
        }        
        return noOfRowsAffected;
    }
    
}
